﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Test.Model;

namespace Test.DAL
{
    public class ClassInfoDAL:BaseDAL<ClassInfo>
    { 
       
       
        //public static DataTable Select(string name = "")
        //{
        //    var sql = $"select * from ClassInfo where name like '%{name}%'";
        //    return DBHelper.Query(sql);
        //}

        public  List<ClassInfo> Select(string name = "")
        {

            return Select(p => p.Name.Contains(name));
        }



        //public static int Delete(int id)
        //{
        //    var sql = $"delete from ClassInfo where id={id}";
        //    return DBHelper.NonQuery(sql);
        //}

        //public  ClassInfo Select(int id)
        //{
            
        //    //model.ClassInfoes.FirstOrDefault(p => p.Id == id)
        //    return Model.ClassInfoes.Find(id);//FirstOrDefault LastOrDefault

        //}
       


        public  int Update(ClassInfo info)
        {
          
            var cls= Model.ClassInfoes.Find(info.Id);
            if (cls != null)
            {
                cls.Name = info.Name;
                cls.Comment = info.Comment;
            }
            return Model.SaveChanges();
        }
    }
}